/*************************************************
* Title：TinyToolKit
* Author：Opportunity 
* Describe：
* CreateTime：2020-07-31 11:59:02
* Version：1.0
* Modify Recorder：
*************************************************/

using System;
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;

namespace TinyToolKitEditor
{
    public class TinyToolWindowUtil : EditorWindow
    {
        public static int DrawPopup(int selectedIndex, string[] displayedOptions)
        {
            return EditorGUILayout.Popup(selectedIndex, displayedOptions, GUILayout.MaxWidth(300));
        }

        public static Enum DrawEnumPopup (string label, Enum selected)
        {
            return EditorGUILayout.EnumPopup(label, selected, GUILayout.MaxWidth(300));  
        }

        public static void DrawBoldLabel(string label)
        {
            EditorGUILayout.LabelField(label, EditorStyles.boldLabel);
        }

        public static void DrawTableHead(string label,string label2)
        {
            EditorGUILayout.LabelField(label,label2);
            EditorGUILayout.LabelField("", new GUIStyle("EyeDropperHorizontalLine"));
        }

        public static void DrawTableTail(string label, string label2)
        {
            EditorGUILayout.Space();
            EditorGUILayout.LabelField(label, label2);
        }

        public static string DrawTextField(string label,string text)  
        {
            return EditorGUILayout.TextField(label,text, GUILayout.MaxWidth(300));
        }

        public static void DrawWarnningDialog(string msg)
        {
            EditorUtility.DisplayDialog("警告", msg, "确认");
        }
        
        public static bool DrawButton (string text)
        {
            return GUILayout.Button(text, GUILayout.Height(25));
        }
        
        public static void DrawDefaultEditorGUI()
        {
            EditorGUILayout.Space();
            
            if (EditorApplication.isPlaying == false)
            {
                EditorGUILayout.HelpBox("运行状态时获取更多信息！", MessageType.Info);
            }
        }

        public static ReorderableList GetReorderableList(SerializedObject serializedObject,string propertyPath,string header,string fieldName)
        {
            ReorderableList reorderableList = new ReorderableList(serializedObject, serializedObject.FindProperty(propertyPath)
                , true, true, true, true);
            
            reorderableList.drawHeaderCallback = rect =>
            {
                GUI.Label(rect, header);
            };

            reorderableList.drawElementCallback = (rect, index, selected, focused) =>
            {
                SerializedProperty item = reorderableList.serializedProperty.GetArrayElementAtIndex(index);
                rect.height = EditorGUIUtility.singleLineHeight;
                rect.y += 2;
                EditorGUI.PropertyField(rect, item, new GUIContent(fieldName + " " + index.ToString()));
            };
            return reorderableList;
        }
    }
}

